/**
 * 
 */
package com.dsteiner.xelavos.client;

import com.dsteiner.widgets.client.JsUtil;
import com.dsteiner.widgets.client.PopupOverlayWidget;
import com.dsteiner.widgets.client.RateItWidget;
import com.dsteiner.widgets.client.RoundBorder;
import com.dsteiner.widgets.client.RoundBorder.RoundBorderModel;
import com.dsteiner.widgets.client.Widgets.FlowPanelExt;
import com.dsteiner.widgets.client.Widgets.HTMLExt;
import com.dsteiner.widgets.client.Widgets.ImageExt;
import com.dsteiner.widgets.client.Widgets.LazyWidget;
import com.dsteiner.widgets.client.event.EventManagerImpl;
import com.dsteiner.widgets.client.model.PopupOverlayModel;
import com.dsteiner.widgets.client.model.RateItModel;
import com.dsteiner.widgets.client.resources.RoundBorderCssResource;
import com.dsteiner.widgets.client.resources.RoundBorderResources;
import com.dsteiner.xelavos.client.controller.DisplayController;
import com.dsteiner.xelavos.client.model.AuthenticationModel;
import com.dsteiner.xelavos.client.model.CommentsModel;
import com.dsteiner.xelavos.client.model.DisplayModel;
import com.dsteiner.xelavos.client.resources.XelavosCssResource;
import com.dsteiner.xelavos.client.resources.XelavosImageBundle;
import com.dsteiner.xelavos.client.resources.XelavosResources;
import com.google.gwt.dom.client.Style.Cursor;
import com.google.gwt.user.client.ui.AbstractImagePrototype;
import com.google.gwt.user.client.ui.FormPanel;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Widget;

public class DisplayWidget extends LazyWidget{
	private final DisplayModel displayModel;
	private DisplayController displayController = new DisplayController();
	private final AuthenticationModel authenticationModel;
	public DisplayWidget(DisplayModel displayModel, 
			AuthenticationModel authenticationModel) {
		this.displayModel = displayModel;
		this.authenticationModel = authenticationModel;
	}
	
	@Override
	public Widget createContentWidget() {
		FlowPanelExt mainPanel = new FlowPanelExt();
		ImageExt image = new ImageExt();
		HTMLExt xelavosImageHtml = new HTMLExt("foto eligido de XelaVos");
		HTMLExt editLink = new HTMLExt("<a href=\"javascript:void(0);\">editar datos</a>");
		HTMLExt removeLink = new HTMLExt("<a href=\"javascript:void(0);\">borrar</a>");
		HTMLExt noImageHtml = new HTMLExt("no hay foto");
		HTMLExt infoHtml = new HTMLExt();
		RateItModel rateItModel = new RateItModel();
		RateItWidget rateItWidget = new RateItWidget(rateItModel);
		HorizontalPanel feedbackPanel = new HorizontalPanel();
		HTMLExt sendLinkHtml = new HTMLExt();
		HTMLExt userHtml = new HTMLExt();
		HTMLExt ratingCountHtml = new HTMLExt();
		HTMLExt commentsHtml = new HTMLExt();
		PopupOverlayModel commentsPopupOverlayModel = new PopupOverlayModel();
		PopupOverlayWidget commentsPopupOverlayWidget = new PopupOverlayWidget(commentsPopupOverlayModel);
		CommentsModel commentsModel = new CommentsModel();;
		CommentsWidget commentsWidget = new CommentsWidget(commentsModel, authenticationModel);
		commentsPopupOverlayModel.setContentWidget(commentsWidget);
		PopupOverlayModel userPopupOverlayModel = new PopupOverlayModel();
		PopupOverlayWidget userPopupOverlayWidget = new PopupOverlayWidget(userPopupOverlayModel);
		DisplayModel userDisplayModel = new DisplayModel();
		DisplayWidget userDisplayWidget = new DisplayWidget(userDisplayModel, authenticationModel);
		userPopupOverlayModel.setContentWidget(userDisplayWidget);
		RoundBorderCssResource css = RoundBorderResources.Util.INSTANCE.css();
		RoundBorderModel roundBorderModel = new RoundBorderModel();
		roundBorderModel.setContentWidget(mainPanel);
		roundBorderModel.setCssResource(css);
		RoundBorder decoratorPanel = new RoundBorder(roundBorderModel);
		Image trackCommentsIcon = new Image();
		AbstractImagePrototype trackCommentsPrototype = XelavosImageBundle.Util.getInstance().trackCommentsIcon(); 
		AbstractImagePrototype trackCommentsSelectedPrototype = XelavosImageBundle.Util.getInstance().trackCommentsSelectedIcon(); 
		ImageExt sendMessageIcon = new ImageExt(XelavosImageBundle.Util.getInstance().sendMessageIcon().createImage()); 
		FormPanel formPanel = new FormPanel();
		formPanel.setMethod(FormPanel.METHOD_POST);
		formPanel.setAction("http://twitter.com/statuses/public_timeline.rss?windowname=true");
		
		sendMessageIcon.setTitle("mandar un mensaje al usuario");
		
		feedbackPanel.setSpacing(5);
		feedbackPanel.add(trackCommentsIcon);
		feedbackPanel.add(commentsHtml);
		feedbackPanel.add(rateItWidget);
		feedbackPanel.add(ratingCountHtml);
		
		mainPanel.add((Widget)image);
		mainPanel.add((Widget)editLink);
		mainPanel.add((Widget)removeLink);
		mainPanel.add((Widget)xelavosImageHtml);
		mainPanel.add((Widget)noImageHtml);
		mainPanel.add((Widget)infoHtml);
		mainPanel.add((Widget)sendMessageIcon);
		mainPanel.add(feedbackPanel);
		mainPanel.add((Widget)userHtml);
		mainPanel.add((Widget)sendLinkHtml);
		mainPanel.add((Widget)formPanel);

		commentsHtml.getElement().getStyle().setProperty("cursor", "pointer");
		noImageHtml.addStyleName(XelavosResources.INSTANCE.css().noImgHtml());
		image.addStyleName(XelavosResources.INSTANCE.css().mainImg());
		setStyleName(XelavosResources.INSTANCE.css().displayWidget());
		feedbackPanel.addStyleName(XelavosResources.INSTANCE.css().feedbackPanel());
		xelavosImageHtml.addStyleName(XelavosResources.INSTANCE.css().xelavosImageHtml());
		editLink.addStyleName(XelavosResources.INSTANCE.css().editLink());
		removeLink.addStyleName(XelavosResources.INSTANCE.css().removeLink());
		sendLinkHtml.addStyleName(XelavosResources.INSTANCE.css().sendLinkIcon());
		trackCommentsIcon.getElement().getStyle().setCursor(Cursor.POINTER);
		
		displayController.registerLazyWidget(this);
		displayController.registerFormPanel(formPanel);
		displayController.registerSendLinkHtml(sendLinkHtml);
		displayController.registerSendMessageIcon(sendMessageIcon);
		displayController.registerTrackCommentsIcon(trackCommentsIcon);
		displayController.registerTrackCommentsPrototype(trackCommentsPrototype);
		displayController.registerTrackCommentsSelectedPrototype(trackCommentsSelectedPrototype);
		displayController.registerRemoveLink(removeLink);
		displayController.registerEditLink(editLink);
		displayController.registerXelavosImageHtml(xelavosImageHtml);
		displayController.registerDisplayModel(displayModel);
		displayController.registerImage(image);
		displayController.registerNoImage(noImageHtml);
		displayController.registerInfoHtml(infoHtml);
		displayController.registerRateItWidget(rateItWidget);
		displayController.registerRateItModel(rateItModel);
		displayController.registerEventManager(EventManagerImpl.getInstance());
		displayController.registerRatingCountHtml(ratingCountHtml);
		displayController.registerAuthenticationModel(authenticationModel);
		displayController.registerCommentsHtml(commentsHtml);
		displayController.registerCommentsPopupOverlayModel(commentsPopupOverlayModel);
		displayController.registerCommentsModel(commentsModel);
		displayController.registerUserHtml(userHtml);
		displayController.registerUserPopupOverlayModel(userPopupOverlayModel);
		displayController.registerUserDisplayModel(userDisplayModel);
		displayController.registerJsUtil(JsUtil.getInstance());
		return decoratorPanel;
	}
}